package com.kogi.patterns;

import java.util.ArrayList;

import android.app.Activity;
import android.database.DataSetObserver;
import android.graphics.Color;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListAdapter;
import android.widget.TextView;

public class MyExpandableListAdapter extends BaseExpandableListAdapter  {

Activity act;

private ArrayList<String> groups;
private ArrayList<String> temp;
private ArrayList<ArrayList<String>> children;

//private String[] groups = { "Highlight important functionalities? ", "Let users find their way through a vast amount of content? ","Let users move through content? ","Let users toggle between different sections or activities? ","Provide access to contextual actions? ","Provide access to general operations for the current screen? " };
//   private String[][] children = {{ "AChild1" },{ "AChild2" }, { "AChild3" },{ "AChild4" }, { "AChild5" }, { "Child1" },{ "Child2" }, { "Child3" },{ "Child4" }, { "Child5" } };
   	
	
	   public MyExpandableListAdapter(Activity a) {
		act =a;// TODO Auto-generated constructor stub
		
		groups = new ArrayList<String>();
		temp = new ArrayList<String>();
		children = new ArrayList<ArrayList<String>>();
		
		groups.add("Highlight important functionalities?");
		groups.add("Let users find their way through a vast amount of content? ");
		groups.add("Let users move through content?");
		groups.add("Let users toggle between different sections or activities? ");
		groups.add("Provide access to contextual actions? ");
		groups.add("Provide access to general operations for the current screen?");
		//1
		temp.add("Action Bar");
		temp.add("Dashboard-Categories");
		temp.add("Dashboard-Features");
		children.add(temp);
		//2
		temp=null;
		temp = new ArrayList<String>();
		temp.add("Drill down navigation");
		temp.add("List navigation");
		temp.add("Segmented control");
		temp.add( "Expandable list");
		temp.add( "Mode selector");
		temp.add( "Tabs");
		temp.add( "Window shade");
		temp.add( "Scroll thumb");
		temp.add( "Slideable top navigation");
		children.add(temp);
		
		//3
		temp=null;
		temp = new ArrayList<String>();
		temp.add( "Carousel");
		temp.add( "Stepping");
		temp.add( "Scroll thumb");
		children.add(temp);
		
		//4
		temp=null;
		temp = new ArrayList<String>();
		temp.add( "Tab bar");
		temp.add( "Mode selector");
		temp.add( "Window shade");
		temp.add( "Slideable top navigation");
		children.add(temp);
		//5
		temp=null;
		temp = new ArrayList<String>();
		temp.add( "Context menu");
		temp.add( "Quick actions");
		temp.add( "Swipe for action");
		children.add(temp);
		//6
		temp=null;
		temp = new ArrayList<String>();
		temp.add( "Options menu");
		temp.add( "Expanded option menu");
		temp.add( "Toolbar");
		children.add(temp);
	}



	
   @Override
   public Object getChild(int groupPosition, int childPosition) {
	   return children.get(groupPosition).get(childPosition);

   }
   @Override
   public long getChildId(int groupPosition, int childPosition) {
       return childPosition;
   }
   @Override
   public int getChildrenCount(int groupPosition) {
	   return children.get(groupPosition).size();

   }
   
   public TextView getGenericView() {
       // Layout parameters for the ExpandableListView
       AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
           ViewGroup.LayoutParams.FILL_PARENT, 64);

       TextView textView = new TextView(act);
       textView.setLayoutParams(lp);
       // Center the text vertically
       textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
       textView.setTextColor(Color.parseColor("#ffffff"));
       // Set the text starting position
       textView.setPadding(36, 0, 0, 0);
       return textView;
   }
   
   @Override
   public View getChildView(int groupPosition, int childPosition,
       boolean isLastChild, View convertView, ViewGroup parent) {
       TextView textView = getGenericView();
       textView.setText(getChild(groupPosition, childPosition).toString());
       return textView;
   }
   @Override

   public Object getGroup(int groupPosition) {
	   return groups.get(groupPosition);

   }
   @Override

   public int getGroupCount() {
	   return groups.size();

   }
   @Override

   public long getGroupId(int groupPosition) {
       return groupPosition;
   }
   @Override

   public View getGroupView(int groupPosition, boolean isExpanded,View convertView, ViewGroup parent) {
       TextView textView = getGenericView();
       textView.setText( getGroup(groupPosition).toString());
       return textView;
   }
   @Override

   public boolean isChildSelectable(int groupPosition, int childPosition) {
       return true;
   }
   @Override

   public boolean hasStableIds() {
       return true;
   }

   }
